import asyncio
import time
from mavsdk import System

async def run():

    #drone = System()
    #await drone.connect(system_address="udp://0.0.0.0:14540")

    autopilot = System()
    await autopilot.connect(system_address="udpin://0.0.0.0:14551")

    '''
    Обработка подключения к FC
    print("Waiting for drone to connect...")
    async for state in drone.core.connection_state():
        if state.is_connected:
            print(f"-- Connected to drone!")
            break
    '''

    '''
    Обработка подключения к GCS
    '''
    print("Waiting for autopilot to connect...")
    async for state in autopilot.core.connection_state():
        if state.is_connected:
            print(f"-- Connected to autopilot!")
            break

    '''
    Предстартовая проверка
    '''
    '''
    print("Waiting for drone to have a global position estimate...")
    async for health in drone.telemetry.health():
        if health.is_global_position_ok and health.is_home_position_ok:
            print("-- Global position estimate OK")
            break

    '''
    while(True):
        print("FF")
        time.sleep(1)

if __name__ == "__main__":
    asyncio.run(run())
